﻿using System;
using System.IO;
using System.Windows.Forms;
using System.Data;
using SystemCustomers.DBUtils;

namespace SystemCustomers.ManageProjectToCustomers
{
    class ManageViewingProjectToCompany
    {
        public DataTable InitializeListProjectCompany()
        {
            return SingletonManagerDb.Instance.DbViewingProjectToCompany();
        }

        public DialogResult EditProjectCompany(DataGridViewRow dr)
        {
            var companyId = dr.Cells["idCompany"].Value.ToString();
            var projectId = dr.Cells["ProjectId"].Value.ToString();
            var destination = SingletonManagerDb.Instance.DbViewingProjectToCompany(projectId, companyId).Rows[0]["destination"].ToString();
            var companyName = dr.Cells["NameCompany"].Value.ToString();
            var projectName = dr.Cells["NameProject"].Value.ToString();
            var priceType = dr.Cells["priceType"].Value.ToString();
            var discription = dr.Cells["Discription"].Value.ToString();
            var paid = dr.Cells["paid"].Value.ToString();
            using (
                var editData = new AddProjectCustomers(companyName, projectName, companyId, projectId,
                                                       priceType,
                                                       discription,
                                                       paid,
                                                       destination,
                                                       DateTime.Parse(dr.Cells["DateStartProject"].Value.ToString()),
                                                       DateTime.Parse(dr.Cells["DateFinishProject"].Value.ToString())))
            {
                editData.btnAdd.Visible = false;
                return editData.ShowDialog();
            }
        }

        public void DeleteProjectCompany(DataGridViewRow dr)
        {
            string companyId = dr.Cells["idCompany"].Value.ToString();
            string projectId = dr.Cells["ProjectId"].Value.ToString();
            string path = dr.Cells["destination"].Value.ToString();
            string allPath = String.Format("{0}\\DataFiles\\{1}\\",System.Windows.Forms.Application.StartupPath, companyId);
          //  if (path != string.Empty) File.Delete(allPath);
            SingletonManagerDb.Instance.DeleteRowProjectToCompany(companyId, projectId);
        }
    }
}
